#ifndef __H_SIEMENS_S7_PRIVATE_H__
#define __H_SIEMENS_S7_PRIVATE_H__

#include "siemens_s7_comm.h"

//private byte[] plcHead1 = "03 00 00 16 11 E0 00 00 00 02 00 C1 02 01 00 C2 02 01 02 C0 01 0A".ToHexBytes( );
//private byte[] plcHead2 = "03 00 00 19 02 F0 80 32 01 00 00 02 00 00 08 00 00 F0 00 00 01 00 01 01 E0".ToHexBytes( );
byte g_plc_head1[] =
{
	0x03,0x00,0x00,0x16,0x11,0xE0,0x00,0x00,0x00,0x01,
	0x00,0xC0,0x01,0x0A,0xC1,0x02,0x01,0x02,0xC2,0x02,
	0x01,0x00
};
byte g_plc_head2[] =
{
	0x03,0x00,0x00,0x19,0x02,0xF0,0x80,0x32,0x01,0x00,
	0x00,0x04,0x00,0x00,0x08,0x00,0x00,0xF0,0x00,0x00,
	0x01,0x00,0x01,0x01,0xE0
};
byte g_plc_order_number[] =
{
	0x03,0x00,0x00,0x21,0x02,0xF0,0x80,0x32,0x07,0x00,
	0x00,0x00,0x01,0x00,0x08,0x00,0x08,0x00,0x01,0x12,
	0x04,0x11,0x44,0x01,0x00,0xFF,0x09,0x00,0x04,0x00,
	0x11,0x00,0x00
};

byte g_plc_head1_200smart[22] =
{
	0x03,0x00,0x00,0x16,0x11,0xE0,0x00,0x00,0x00,0x01,
	0x00,0xC1,0x02,0x10,0x00,0xC2,0x02,0x03,0x00,0xC0,
	0x01,0x0A
};

byte g_plc_head2_200smart[25] =
{
	0x03,0x00,0x00,0x19,0x02,0xF0,0x80,0x32,0x01,0x00,
	0x00,0xCC,0xC1,0x00,0x08,0x00,0x00,0xF0,0x00,
	0x00,0x01,0x00,0x01,0x03,0xC0
};

byte g_plc_head1_200[22] =
{
	0x03,0x00,0x00,0x16,0x11,0xE0,0x00,0x00,0x00,0x01,
	0x00,0xC1,0x02,0x4D,0x57,0xC2,0x02,0x4D,0x57,0xC0,
	0x01,0x09
};

byte g_plc_head2_200[25] =
{
	0x03,0x00,0x00,0x19,0x02,0xF0,0x80,0x32,0x01,0x00,
	0x00,0x00,0x00,0x00,0x08,0x00,0x00,0xF0,0x00,0x00,
	0x01,0x00,0x01,0x03,0xC0
};

const byte g_s7_stop[] = {
	0x03, 0x00, 0x00, 0x21, 0x02, 0xf0, 0x80, 0x32, 0x01, 0x00,
	0x00, 0x0e, 0x00, 0x00, 0x10, 0x00, 0x00, 0x29, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x09, 0x50, 0x5f, 0x50, 0x52, 0x4f, 0x47,
	0x52, 0x41, 0x4d
};

const byte g_s7_hot_start[] = {
	0x03, 0x00, 0x00, 0x25, 0x02, 0xf0, 0x80, 0x32, 0x01, 0x00,
	0x00, 0x0c, 0x00, 0x00, 0x14, 0x00,	0x00, 0x28, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x00, 0x09, 0x50, 0x5f,
	0x50, 0x52, 0x4f, 0x47, 0x52, 0x41, 0x4d
};

const byte g_s7_cold_start[] = {
	0x03, 0x00, 0x00, 0x27, 0x02, 0xf0, 0x80, 0x32, 0x01, 0x00,
	0x00, 0x0f, 0x00, 0x00, 0x16, 0x00, 0x00, 0x28, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x02, 0x43, 0x20, 0x09,
	0x50, 0x5f,	0x50, 0x52, 0x4f, 0x47, 0x52, 0x41, 0x4d
};

///////////////////////////////////////////////////////////////////////////
const byte g_pdu_start = 0x28;            // CPU start
const byte g_pdu_stop = 0x29;             // CPU stop
const byte g_pdu_already_started = 0x02;   // CPU already in run mode
const byte g_pdu_already_stopped = 0x07;   // CPU already in stop mode

byte g_plc_rack = 0x00;
byte g_plc_slot = 0x00;
int g_pdu_length = 0;

s7_error_code_e s7_read_response(int fd, byte_array_info* response, int* read_count);

void s7_initialization(siemens_plc_types_e plc, char* ip);

//////////////////////////////////////////////////////////////////////////
s7_error_code_e read_bit_value(int fd, const char* address, int length, byte_array_info* out_bytes);
s7_error_code_e read_byte_value(int fd, const char* address, int length, byte_array_info* out_bytes);
s7_error_code_e read_address_data(int fd, siemens_s7_address_data address_data, byte_array_info* out_bytes);

s7_error_code_e write_bit_value(int fd, const char* address, int length, bool value);
s7_error_code_e write_byte_value(int fd, const char* address, int length, byte_array_info in_bytes);
s7_error_code_e write_address_data(int fd, siemens_s7_address_data address_data, byte_array_info in_bytes);

//////////////////////////////////////////////////////////////////////////
bool initialization_on_connect(int fd);

#endif//__H_SIEMENS_S7_PRIVATE_H__
